'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class Video extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // 多对多关联到分类
      this.belongsToMany(models.Category, {
        through: 'VideoCategories',
        as: 'categories',
        foreignKey: 'video_id',
        otherKey: 'category_id'
      });
    }
  }
  Video.init({
    title: DataTypes.STRING,
    description: DataTypes.TEXT,
    cover_url: DataTypes.STRING,
    video_url: DataTypes.STRING,
    duration: DataTypes.INTEGER,
    views: DataTypes.INTEGER,
    likes: DataTypes.INTEGER,
    favorites: DataTypes.INTEGER,
    status: DataTypes.INTEGER,
    user_id: DataTypes.INTEGER
  }, {
    sequelize,
    modelName: 'Video',
    paranoid: false // 禁用软删除
  });
  return Video;
};